package com.byght.bygsystem.mapper;

import com.byght.bygsystem.model.Transaction;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
@Mapper
@Repository
public interface TransactionMapper {
    @Select("SELECT * FROM Transactions WHERE id = id = #{id}")
    Transaction getTransactionById(int id);

    @Select("SELECT * FROM Transactions")
    List<Transaction> getAllTransactions();

    @Insert("INSERT INTO Transactions(date, type, amount, description, created_at, updated_at) VALUES(#{date}, #{type}, #{amount}, #{description}, #{createdAt}, #{updatedAt})")
    void insertTransaction(Transaction transaction);

    @Update("UPDATE Transactions SET date=#{date}, type=#{type}, amount=#{amount}, description=#{description}, updated_at=#{updatedAt} WHERE id = #{id}")
    void updateTransaction(Transaction transaction);

    @Delete("DELETE FROM Transactions WHERE id = #{id}")
    void deleteTransaction(int id);
}
